package com.company.test29;


/**
 * Created by Administrator on 2016.11.16.
 */
public class Test2901 {
    public static void main(String[] args) {
        Runnable printA=new PrintChar('a',100);
        Runnable printB=new PrintChar('b',100);
        Runnable print100=new PrintNum(100);

        Thread thread1=new Thread(printA);
        Thread thread2=new Thread(printB);
        Thread thread3=new Thread(print100);

        thread3.start();
    }

    static class PrintChar implements Runnable{
        private char charToPrint;
        private int times;

        public PrintChar(char c,int t){
            charToPrint=c;
            times=t;
        }

        @Override
        public void run() {
            for(int i=0;i<times;i++){
                System.out.print(charToPrint+" ");
            }
        }
    }

    static class PrintNum implements Runnable{
        private int lastNum;

        public PrintNum(int n){
            lastNum=n;
        }

        @Override
        public void run() {
            Thread thread=new Thread(new PrintChar('c',30));
            thread.start();

            try {
                for(int i=0;i<lastNum;i++){
                    System.out.print(i+" ");
                    if(i==50) thread.join();
                }
            }catch (InterruptedException ex){

            }
        }
    }
}